package mint.modules.generator;

import java.util.Formatter;
import java.util.List;

import mint.modules.generator.expression.ExprNode;
import mint.modules.generator.expression.Expression;
import mint.modules.generator.expression.ExpressionType;
import mint.modules.type.Type;

import org.antlr.runtime.tree.Tree;

public class ExpressionStatementNode extends Scope implements MintNode {
	private Expression expr;

	public ExpressionStatementNode(Scope theParent, Tree exprStmtTree) {
		super(theParent, theParent.containerClass);
		expr = new ExprNode(theParent, ExpressionType.Right, exprStmtTree.getChild(0));
	}

	@Override
	public void testSemantic() {
		expr.testSemantic();
	}

	@Override
	public List<String> getSemanticErrors() {
		return expr.getSemanticErrors();
	}

	@Override
	public void emit(Formatter output) {
		expr.emit(output);
		
		if(!expr.getType().equals(Type.voidType))
			output.format("pop\n");
	}

	@Override
	public int getLine() {
		return expr.getLine();
	}

	@Override
	public void printSymbolTable(Formatter output, int tabSize) {}
}
